// written by Jonathan Odom and Aneesh Butani and Ray Zeller

#include "Day.h"
#include "DayTime.h"

const string FREE = "&nbsp;";
const string TILDASPACE = "~ ";
Day::Day()
{
}

Day::Day(const vector<Event*>& events, bool allDay)
: myEvents(events)
//,allDayEvent(allDay)
{
}

vector<string> Day::dayList(){
	vector<string> list;
	int hour = 0;
	int minute = 0;
	for (vector<Event*>::iterator it = myEvents.begin(); it!=myEvents.end(); ++it) {
		DayTime dt = DayTime((*it)->Event::getStart());
		DayTime dtEnd = DayTime((*it)->Event::getEnd());
		while((dt.getHourInt() > hour)||
		(dt.getHourInt() == hour && dt.getMinuteInt()>minute)){
			list.push_back(FREE);
			minute++;
			if(minute >= 60){
				hour++;
				minute = 0;
			}
		}
		while(((dtEnd.getHourInt() > hour)||
		(dtEnd.getHourInt() == hour && dtEnd.getMinuteInt()>minute))){
			vector<Event*>::iterator iterTemp = it;
			++iterTemp;
			DayTime dtTemp = DayTime((*iterTemp)->Event::getStart());
			DayTime dtTempEnd = DayTime((*iterTemp)->Event::getEnd());
			if(iterTemp!=myEvents.end()){
				if(dtTemp.getHourInt() < hour && dtTempEnd.getHourInt() >hour || (
				dtTempEnd.getHourInt()==hour && dtTempEnd.getMinuteInt() >= minute))
					list.push_back((*it)->Event::getDescription() + TILDASPACE + (*iterTemp)->Event::getDescription());
				else if((dtTemp.getHourInt() == hour && dtTemp.getMinuteInt() <= minute) &&
						dtTempEnd.getHourInt() >hour || dtTempEnd.getHourInt()==hour && 
						dtTempEnd.getMinuteInt() >= minute)
					list.push_back((*it)->Event::getDescription() + TILDASPACE + (*iterTemp)->Event::getDescription());
				else
					list.push_back((*it)->Event::getDescription());
			}
			else
				list.push_back((*it)->Event::getDescription());
			minute++;
			if(minute >= 60){
				hour++;
				minute = 0;
			}
		}
	}
	while(hour<24){
		list.push_back(FREE);
		minute+=1;
			if(minute >= 60){
				hour++;
				minute = 0;
			}
	}
	return list;
}
Day::~Day()
{
}
